package com.weixing.mall.provider.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.weixing.mall.provider.mapper.GoodsSceneMapper;
import com.weixing.mall.provider.model.domain.GoodsScene;
import com.weixing.mall.provider.service.IGoodsSceneService;
import com.weixing.mall.util.ListUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

/**
 * @Author wx
 * @Date 2019/8/13 16:59
 * @Version 1.0
 */
/**
 * <p>
 * 商品模块-商品场景关联表 服务实现类
 * </p>
 *
 * @author Small
 * @since 2019-11-20
 */
@Service
public class GoodsSceneServiceImpl extends ServiceImpl<GoodsSceneMapper, GoodsScene> implements IGoodsSceneService {
    @Autowired
    private GoodsSceneMapper goodsSceneMapper;

    @Override
    public void save(Long id, Long[] sceneId) {
        ArrayList<GoodsScene> goodsScenes = new ArrayList<>();
        for(int i=0;i<sceneId.length;i++){
            GoodsScene goodsScene = new GoodsScene();
            goodsScene.setGoodsId(id);
            goodsScene.setSceneId(sceneId[i]);
            goodsScenes.add(i,goodsScene);
        }
        //先将原有的数据进行删除
        goodsSceneMapper.delAllByGoods(goodsScenes);
         //删除后，在将数据添加
        saveBatch(goodsScenes, ListUtil.SIZE);
    }
}
